﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog.Fluent;
using SuperX.Common;
using SuperX.Common.Log;
using SuperX.SuperSocket.Server;
using SuperSocket.SocketBase.Command;
using SuperX.SuperSocket.Socket.Server;
using SuperX.SuperSocket.Socket.Message;

namespace SuperX.SuperSocket.Socket.Command
{
    public class MessageCommand : CommandBase<Session, MessageRequestInfo>
    {
        public override string Name => "SendObject";

        public override void ExecuteCommand(Session session, MessageRequestInfo requestInfo)
        {
            try
            {
                CommandTransfer.FireMessageReceived(session, new MessageEventArgs(session, requestInfo.Body));
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
            }
        }
    }

    public class MessageEventArgs : EventArgs
    {
        public Session AppSession { get; set; }

        public SocketMessage SocketMessage { get; set; }

        public MessageEventArgs(Session appSession, SocketMessage socketMessage)
        {
            AppSession = appSession;
            SocketMessage = socketMessage;
        }
    }
}